const fs = require('fs')

const rs = fs.createReadStream('./res/test.txt', {
    highWaterMark: 4
})

const ws = fs.createWriteStream('./res/test1.txt', {
    highWaterMark: 2
})

let flag = true
rs.on('data', (chunk) => {
    flag = ws.write(chunk)
    if (!flag) {
        rs.pause()
    }
})

ws.on('drain', () => {
    rs.resume()
})